package com.ep.thirdPlatformProject.job.service.impl;

import cn.hutool.core.date.DateTime;
import com.ep.thirdPlatformProject.job.service.MayCurToErpService;
import com.ep.thirdPlatformProject.maycur.common.Constant;
import com.ep.thirdPlatformProject.maycur.helper.MayCurLoanHelper;
import com.ep.thirdPlatformProject.maycur.helper.MayCurReimburseHelper;
import com.xxl.job.core.context.XxlJobHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
@RequiredArgsConstructor
public class MayCurToErpServiceImpl implements MayCurToErpService {

    private final MayCurLoanHelper loanHelper;

    private final MayCurReimburseHelper reimburseHelper;

    @Override
    public Map<String, BigDecimal> getTotalAmountMap(DateTime dateTime) {


        Map<String, BigDecimal> totalAmountMap = new HashMap<>();
        Map<String, BigDecimal> loanAmountMap = loanHelper.getLoanAmount(dateTime);
        XxlJobHelper.log("借款单今日费用合计：{}，本月费用合计：{}，本年费用合计：{}",
                loanAmountMap.get(Constant.DAY_TOTAL_EXPENSE_AMOUNT),
                loanAmountMap.get(Constant.MONTH_TOTAL_EXPENSE_AMOUNT),
                loanAmountMap.get(Constant.YEAR_TOTAL_EXPENSE_AMOUNT)
        );
        log.info("借款单:{}", loanAmountMap);


        Map<String, BigDecimal> reimburseAmountMap = reimburseHelper.getReimburseAmount(dateTime);
        XxlJobHelper.log("报销单今日费用合计：{}，本月费用合计：{}，本年费用合计：{}",
                reimburseAmountMap.get(Constant.DAY_TOTAL_EXPENSE_AMOUNT),
                reimburseAmountMap.get(Constant.MONTH_TOTAL_EXPENSE_AMOUNT),
                reimburseAmountMap.get(Constant.YEAR_TOTAL_EXPENSE_AMOUNT)
        );
        log.info("报销单:{}", reimburseAmountMap);

        loanAmountMap.forEach((k1, v1) -> {
            reimburseAmountMap.forEach((k2, v2) ->
                    {
                        if (k2.equals(k1)) {
                            totalAmountMap.put(k1, v1.add(v2));
                        }
                    }
            );
        });
        return totalAmountMap;
    }
}
